package com.example.cardgame.model2

import java.util.Random

// 定义 Deck 类，表示一副牌
class Deck() {
    // 卡片列表
    private val cards = mutableListOf<Card>()
    // 随机数生成器
    private val r = Random()

    // 初始化块，创建一副牌并添加所有卡片
    init {
        for (suit in Card.validSuits) {
            for (rank in Card.rankStrings) {
                val card = Card(suit=suit, rank=rank)
                cards.add(card)
            }
        }
    }

    // 抽取一张随机卡片
    fun drawRandomCard(): Card? {
        var randomCard: Card? = null
        if (cards.size > 0) {
            // 从卡片列表中随机移除一张卡片
            randomCard = cards.removeAt(r.nextInt(cards.size))
        }
        return randomCard
    }
}